/*
 * @Author: zheguo 3188606474@qq.com
 * @Date: 2024-04-19 09:01:45
 * @LastEditors: zheguo 3188606474@qq.com
 * @LastEditTime: 2024-04-19 19:37:50
 * @FilePath: \ProjectAction\express-app\server.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const express = require('express')
const bodyParser = require("body-parser")
const cors = require("cors")
const commodityRouter = require("./app/router/commodityRouter/commodityRouter")
const channelsRouter = require("./app/router/commodityRouter/channelsRouter")
const messageRouter = require("./app/router/messageRouter/messageRouter")
const messageBoardRouter = require("./app/router/MessageBoardRouter/messageBoardRouter")
const loginRouter = require("./app/router/logRouter/logRouter")
const app = new express()
// 解决跨域问题
const corsOption = {
    origin: ["http://localhost:5173", "http://localhost:5174"],
};
// 配置跨域
app.use(cors(corsOption))
// 配置body-parser 解决post请求参数问题 表单数据
app.use(bodyParser.json())
// 配置body-parser 解决post请求参数问题 查询字符串
app.use(bodyParser.urlencoded({extended: true}))
// 引入模型
const db = require("./app/models/index")
// 模型同步
db.sequelize.sync()
// 配置静态资源目录
app.use(express.static(__dirname + "/public"))
// 管理员路由
require("./app/router/adminRouter/admin.router")(app)
// 用户路由
require("./app/router/userRouter/user.router")(app)
// 消息列表路由
app.use("/message", messageRouter)
// 文件上传测试路由
// app.use("/upload", uploadRouter)
// 商品路由
app.use("/commodity", commodityRouter)
// 开发者日志路由
app.use("/log", loginRouter)
// 商品类型路由
app.use("/api", channelsRouter)
// 留言板路由
app.use("/messageBoard", messageBoardRouter)


const PORT = 3031
app.listen(PORT, () => {
    console.log("项目成功运行")
})